package com.singzi.leetcode.N500;

import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

public class T0494 {
    public static void main(String[] args) {
        Solution solution = new Solution();
        int []nums = {1,1,1,1,1};
        System.out.println(solution.findTargetSumWays(nums, 3));

    }

}

class Solution {
    private int cont = 0;
    public int findTargetSumWays(int[] nums, int target) {
        int n = nums.length, sum = 0;
        boolean [][] flags = new boolean[n][2];
        for (int i = 0; i < n; i++) {
            flags[i][0] = true;
            flags[i][1] = false;
        }
        backTrace(nums, 0, n, flags, 0, target);
        return cont;
    }

    private void backTrace(int[] nums, int i, int n, boolean [][] flags, int sum, int target) {
        if(i == n){
            System.out.println(sum);
            if(sum == target){
                cont++;
            }
            return;
        }
        for(boolean flag:flags[i]){
            if(flag) {
                sum += nums[i];
                backTrace(nums, i+1, n, flags, sum, target);
                sum -= nums[i];
            }
            else {
                sum -= nums[i];
                backTrace(nums, i+1, n, flags, sum, target);
                sum += nums[i];
            }



        }
    }
}
class test01{
    public void test01(){
        for(int i = 0;i < 10;i++){
            for (int j = 0; j < 10; j++) {
                for (int k = 0; k < 10; k++) {
                    for (int l = 0; l < 10; l++) {
                        System.out.println(i + k + j + l);
                    }
                }
            }
        }
    }
}

